<template>
    <h2 style="text-align: center;">理财添加</h2>
    <table border="1">
        <tr>
            <td>理财名称</td>
            <td>
                <input type="text" v-model="info.FI_name">
            </td>
        </tr>
        <tr>
            <td>年收益</td>
            <td>
                <input type="text" v-model="info.FI_yearmoney">
            </td>
        </tr>
        <tr>
            <td>利息</td>
            <td>
                <select v-model="info.FT_id">
                    <option value=0>--请选择--</option>
                    <option v-for="item in infos" :value="item.FT_id">{{ item.FT_name }}%</option>
                </select>
            </td>
        </tr>
        <tr>
            <td>最低金额</td>
            <td>
                <input type="text" v-model="info.FI_minmoney">
            </td>
        </tr>
        <tr>
            <td>风险等级</td>
            <td>
                <select v-model="info.FI_grade">
                    <option value="0">--请选择--</option>
                    <option value="低">低风险</option>
                    <option value="低">中风险</option>
                    <option value="低">高风险</option>
                </select>
            </td>
        </tr>
        <tr>
            <td></td>
            <td>
                <input type="button" value="添加" @click="add()">
            </td>
        </tr>
    </table>
</template>
<script setup lang="ts">
import {ref,onMounted} from 'vue'
import {useRouter} from 'vue-router'
import axios from 'axios'

const router=useRouter()

const info=ref({
    FI_name:"",
    FI_yearmoney:"",
    FT_id:0,
    FI_minmoney:"",
    FI_number:"",
    FI_grade:"0"
})

const infos=ref({
    FT_id:0,
    FT_name:""
})




const Bind=()=>{
    axios({
        url:"http://localhost:52342/api/Finan/Bind",
        method:"get",
    })
    .then((res)=>{
        infos.value=res.data
    })
    .catch((err)=>{
        console.log(err)
    })
}
onMounted(()=>{
    Bind()
})

const add=()=>{
    if(info.value.FI_name==""){
        alert("理财名称不能为空")
        return
    }
    
    if(Number(info.value.FI_minmoney)<=0){
        alert("最低金额必须大于0")
        return
    }
    axios({
        url:"http://localhost:52342/api/Finan/FinanAdd",
        method:"post",
        data:info.value
    })
    .then((res)=>{
        if(res.data==-1){
            alert("理财项目名称不能重复")
            return
        }else if(res.data>0){
            alert("添加成功")
            router.push("/FinanShow")
        }else{
            alert("添加失败")
            return
        }
    })
    .catch((err)=>{
        console.log(err)
    })
}


</script>


